/*
** Copyright (C) 2010 Calin Radoni
**
** This file is part of CHScanner.
**
** CHScanner is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** CHScanner is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with CHScanner. If not, see <http://www.gnu.org/licenses/>.
*/

#include "StdAfx.h"
#include "MWmi_Win32_VideoController.h"

//---------------------------------------------------------------------------

MWmi_Win32_VideoController::MWmi_Win32_VideoController(void)
{
	propertyCount = 13;
	Initialize();
}

MWmi_Win32_VideoController::~MWmi_Win32_VideoController(void)
{
	DeleteChild();
}

//---------------------------------------------------------------------------

MWmiInfo* MWmi_Win32_VideoController::CreateChild(void)
{
	MWmi_Win32_VideoController *elem;

	try{
		elem = new MWmi_Win32_VideoController;
	}
	catch(...){
		elem = NULL;
	}
	return elem;
}

void MWmi_Win32_VideoController::DeleteChild(void)
{
	MWmi_Win32_VideoController *elem;
	
	if(next!=NULL){
		elem = (MWmi_Win32_VideoController*)next;
		next = NULL;
		delete elem;
	}
}

//---------------------------------------------------------------------------

void MWmi_Win32_VideoController::Initialize(void)
{
	xAdapterRAM                  = 0;
	xCurrentBitsPerPixel         = 0;
	xCurrentHorizontalResolution = 0;
	xCurrentRefreshRate          = 0;
	xCurrentVerticalResolution   = 0;
	xDescription                 = _T("");
	xDriverDate                  = _T("");
	xDriverVersion               = _T("");
	xInfFilename                 = _T("");
	xInfSection                  = _T("");
	xInstalledDisplayDrivers     = _T("");
	xName                        = _T("");
	xVideoProcessor              = _T("");

}

//---------------------------------------------------------------------------

CString MWmi_Win32_VideoController::GetQueryString(void)
{
	CString str;

	str = _T("select * from Win32_VideoController");
	return str;
}

//---------------------------------------------------------------------------

CString MWmi_Win32_VideoController::GetPropertyName(int idxIn)
{
	CString str;

	switch(idxIn){
		case 0 :
			str = _T("AdapterRAM");
			break;
		case 1 :
			str = _T("CurrentBitsPerPixel");
			break;
		case 2 :
			str = _T("CurrentHorizontalResolution");
			break;
		case 3 :
			str = _T("CurrentRefreshRate");
			break;
		case 4 :
			str = _T("CurrentVerticalResolution");
			break;
		case 5 :
			str = _T("Description");
			break;
		case 6 :
			str = _T("DriverDate");
			break;
		case 7 :
			str = _T("DriverVersion");
			break;
		case 8 :
			str = _T("InfFilename");
			break;
		case 9 :
			str = _T("InfSection");
			break;
		case 10 :
			str = _T("InstalledDisplayDrivers");
			break;
		case 11 :
			str = _T("Name");
			break;
		case 12 :
			str = _T("VideoProcessor");
			break;

		default :
			str = _T("");
			break;
	}

	return str;
}

//---------------------------------------------------------------------------

bool MWmi_Win32_VideoController::SetPropertyValue(int idxIn, VARIANT *vtIn)
{
	if(vtIn==NULL) return true;
	if(vtIn->vt==VT_NULL) return true;

	switch(idxIn){
		case 0 :
			if(vtIn->vt!=VT_I4) return false;
			xAdapterRAM = vtIn->lVal;
			break;
		case 1 :
			if(vtIn->vt!=VT_I4) return false;
			xCurrentBitsPerPixel = vtIn->lVal;
			break;
		case 2 :
			if(vtIn->vt!=VT_I4) return false;
			xCurrentHorizontalResolution = vtIn->lVal;
			break;
		case 3 :
			if(vtIn->vt!=VT_I4) return false;
			xCurrentRefreshRate = vtIn->lVal;
			break;
		case 4 :
			if(vtIn->vt!=VT_I4) return false;
			xCurrentVerticalResolution = vtIn->lVal;
			break;

		case 5 :
			if(vtIn->vt!=VT_BSTR) return false;
			xDescription = vtIn->bstrVal;
			break;
		case 6 :
			if(vtIn->vt!=VT_BSTR) return false;
			xDriverDate = vtIn->bstrVal;
			break;
		case 7 :
			if(vtIn->vt!=VT_BSTR) return false;
			xDriverVersion = vtIn->bstrVal;
			break;
		case 8 :
			if(vtIn->vt!=VT_BSTR) return false;
			xInfFilename = vtIn->bstrVal;
			break;
		case 9 :
			if(vtIn->vt!=VT_BSTR) return false;
			xInfSection = vtIn->bstrVal;
			break;
		case 10 :
			if(vtIn->vt!=VT_BSTR) return false;
			xInstalledDisplayDrivers = vtIn->bstrVal;
			break;
		case 11 :
			if(vtIn->vt!=VT_BSTR) return false;
			xName = vtIn->bstrVal;
			break;
		case 12 :
			if(vtIn->vt!=VT_BSTR) return false;
			xVideoProcessor = vtIn->bstrVal;
			break;

		default :
			return false;
	}

	return true;
}

//---------------------------------------------------------------------------

bool MWmi_Win32_VideoController::SetFromPointer(MWmiInfo* wmiInfoIn)
{
	MWmi_Win32_VideoController *elem;
	MWmi_Win32_VideoController *elemNew;

	DeleteChild();
	Initialize();
	if(wmiInfoIn==NULL) return true;

	elem = (MWmi_Win32_VideoController*)wmiInfoIn;

	xAdapterRAM                  = elem->xAdapterRAM;
	xCurrentBitsPerPixel         = elem->xCurrentBitsPerPixel;
	xCurrentHorizontalResolution = elem->xCurrentHorizontalResolution;
	xCurrentRefreshRate          = elem->xCurrentRefreshRate;
	xCurrentVerticalResolution   = elem->xCurrentVerticalResolution;
	xDescription                 = elem->xDescription;
	xDriverDate                  = elem->xDriverDate;
	xDriverVersion               = elem->xDriverVersion;
	xInfFilename                 = elem->xInfFilename;
	xInfSection                  = elem->xInfSection;
	xInstalledDisplayDrivers     = elem->xInstalledDisplayDrivers;
	xName                        = elem->xName;
	xVideoProcessor              = elem->xVideoProcessor;

	if(elem->next==NULL) return true;

	try{
		elemNew = new MWmi_Win32_VideoController;
	}
	catch(...){
		elemNew = NULL;
	}
	if(elemNew==NULL) return false;

	next = elemNew;

	return elemNew->SetFromPointer(elem->next);
}

//---------------------------------------------------------------------------

bool MWmi_Win32_VideoController::IsEmpty(void)
{
	return xName.IsEmpty() ? true : false;
}

//---------------------------------------------------------------------------
